/*
 * $Id: MPSyntaxGenerator.java,v 1.2 2003/05/31 07:49:20 milca Exp $
 *
 * Copyright (c) Milan Jedlicka
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package net.sf.vofce.metapost;

import java.awt.Dimension;

/** 
 * Provides easy methods witch generates MetaPost commands. 
 * This methods makes code clean, cause it moves all brackets and commas 
 * of MetaPost generating code into this class.
 *
 * @author Milan Jedlicka
 */
public class MPSyntaxGenerator {

 	/**
	 * Default constructor. 
	 */
	public MPSyntaxGenerator() {
	}
	
	/**
	 * Generates MetaPost pair.
	 * Pair in METAPOSt looks like (double, double).
	 * @param 	x	first component of pair
	 * @param 	y	second component of pair
	 */
	public String pair(double x, double y) {
		return "(" + x + ", " + y + ")";
	}

	/**
	 * Generates MetaPost triplet.
	 * @param 	x	first component of pair
	 * @param 	y	second component of pair
	 * @param 	z	third component of pair
	 */
	public String triplet(double x, double y, double z) {
		return "(" + x + "," + y + ", " + z + ")";
	}
	
	/**
	 * Generates MetaPost assignment.
	 * @param 	asgTo	variable where to assign
	 * @param 	asgWhat	value which have to be assigned
	 */
	public String assignment(String asgTo, String asgWhat) {
		return asgTo + " := " + asgWhat + " ;";
	}

	/**
	 * Generates MetaPost command not ended by <code>;</code>.
	 * @param 	com 	command
	 * @param 	args	arguments
	 */
	public String command(String com, String args) {
		return com + " " + args; 	
	}

	/**
	 * Generates MetaPost command. 
	 * @param 	com 	command
	 * @param 	args	arguments
	 */	
	public String commandLine(String com, String args) {
		return command(com, args) + " ;"; 	
	}

	/**
	 * Generates MetaPost procedure not ended by <code>;</code>. 
	 * @param 	name 	procedure name
	 * @param 	args	procedure arguments
	 */	
	public String procedure(String name, String args) {
		return name + "(" + args + ")";
	}

	/**
	 * Generates MetaPost procedure. 
	 * @param 	name 	procedure name
	 * @param 	args	procedure arguments
	 */	
	public String procedureLine(String name, String args) {
		return procedure(name, args) +  " ;";
	}
	
	/**
	 * Generates MetaPost declaration.
	 * @param 	type 	variable type
	 * @param 	var	name of the variable
	 */
	public String declaration(String type, String var) {
		return type + " " + var + " ;";
	}

	/**
	 * Generates MetaPost scaling transformation code.
	 * @param	xscaled <i>x</i> coordinate scaling attribute
	 * @param	yscaled <i>y</i> coordinate scaling attribute
	 */
	public String scale(double xscaled, double yscaled) {
		return "xscaled" + " " + xscaled + " " + "yscaled" + " " + yscaled + " ";
	}

	/**
	 * Generates MetaPost rotate transformation code.
	 * @param	degrees which define rotate angle
	 */
	public String rotate(double degrees) {
		return "rotated" + " " + degrees + " ";	
	}
	
	/**
	 * Generates MetaPost shift transformation code.
	 * @param	pair 	pair which define shift in <i>x</i> and <i>y</i> coordinate
	 */
	public String shift(String pair) {
		return "shifted" + " " + pair + " ";	
	}

	/**
	 * Generates MetaPost shear transformation code.
	 * @param	slant 	how much to slant object in x-coordinate
	 */
	public String shear(double slant) {
		return "slanted" + " " + slant + " ";
	}
	
	/**
	 * Generates MetaPost reflecting transformation code.
	 * Two pairs as arguments defines the axis around which is refleting.
	 * @param	pair1 	first point of axis
	 * @param 	pair2 	second point of axis
	 */
	public String reflect(String pair1, String pair2) {
		return "reflectedabout" + "(" + pair1 + ", " + pair2 + ")";	
	}
}

